#include "StdAfx.h"
#include "CircuitPolylineDisObj.h"


CCircuitPolylineDisObj::CCircuitPolylineDisObj(CCircuitPolyline *pCirPlyline)
	: CCircuitUnitDisObj(pCirPlyline)
{
	m_dblColor[0] = pCirPlyline->GetColorR();
	m_dblColor[1] = pCirPlyline->GetColorG();
	m_dblColor[2] = pCirPlyline->GetColorB();
	m_dblLineWidth = pCirPlyline->GetBorderWidth();
}

CCircuitPolylineDisObj::CCircuitPolylineDisObj(const CCircuitPolylineDisObj *pDisObj, CCircuitPolyline *pCirPlyline/* =NULL */)
	: CCircuitUnitDisObj(pDisObj, pCirPlyline)
{

}

CCircuitPolylineDisObj::~CCircuitPolylineDisObj(void)
{
}

void CCircuitPolylineDisObj::Serialize(CArchive & ar)
{
	CCircuitUnitDisObj::Serialize(ar);
}

void CCircuitPolylineDisObj::Display(CHoopsMap *pHoopsMap)
{
	CCircuitPolyline *pCirPlyline = (CCircuitPolyline *)GetEntityObj();
	if (!pCirPlyline)
	{
		return;
	}

	HC_KEY key_obj = INVALID_KEY;
	char sPlylineSeg[64];
	sprintf(sPlylineSeg, "polyline_%d", pCirPlyline->GetId());
	key_obj = HC_Open_Segment(sPlylineSeg);
		HC_Flush_Contents(".", "everything");

		int count = pCirPlyline->GetPtCount();
		HPoint *pts = new HPoint[count];
		list<double> posList = pCirPlyline->GetPosList();
		list<double>::iterator it_pos = posList.begin();
		for (int i=0; i<count; i++)
		{
			pts[i].x = *it_pos;
			it_pos++;
			pts[i].y= *it_pos;
			it_pos++;
			pts[i].z = 0.0f;
		}
		HC_Insert_Polyline(count, pts);
		delete []pts;

		eLinePattern patt = pCirPlyline->GetLinePattern();
		CStringA szLinePattern;
		CWireDisplayObj::GetLinePattrenText(patt, szLinePattern);
		HC_Set_Line_Pattern(szLinePattern);

		char szColorPattern[64];
		sprintf(szColorPattern, "lines = (r=%.2f g=%.2f b=%.2f)", 
			GetColorR(), GetColorG(), GetColorB());
		HC_Set_Color(szColorPattern);
		if (this->IsVirtualShow())
		{
			HC_Set_Color("faces = ( transmission = (r=0.9 g=0.9 b=0.9) )");
			HC_Set_Color("lines = ( transmission = (r=0.9 g=0.9 b=0.9) )");
			HC_Set_Color("text = ( transmission = (r=0.9 g=0.9 b=0.9) )");
		}
	HC_Close_Segment();

	pHoopsMap->Delete(this);
	pHoopsMap->Add(key_obj, this);
}

void CCircuitPolylineDisObj::Transform(const CMatrix transf)
{

}

CObj *CCircuitPolylineDisObj::Clone() const
{
	return new CCircuitPolylineDisObj(this);
}

bool CCircuitPolylineDisObj::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

eCircuitUnitType CCircuitPolylineDisObj::GetCircuitUnitType() const
{
	return CIRCUIT_POLYLINE_DISOBJ;
}
